// 封装锁
#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;
class Mutex
{
public:
    Mutex()
    {
        pthread_mutex_init(&_lock, nullptr);
    }
    void lock() 
    {
        pthread_mutex_lock(&_lock);
    }
    void Unlock() 
    {
        pthread_mutex_unlock(&_lock);
    }
    pthread_mutex_t* Get()
    {
        return &_lock;
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_lock);
    }

private:
    pthread_mutex_t _lock;
};
class LockGuard
{
    public:
    LockGuard(Mutex* mutex):_mutexp(mutex)
    {
        _mutexp->lock();

    }
    //锁出作用域之后自动析构函数
    ~LockGuard()
    {
         _mutexp->Unlock();
        
    }

    private:
    Mutex* _mutexp;
};